#pragma once

#include "doc/normal_document.h"
#include "doc/convert/attribute_convert/multistring_attribute_convertor.h"
#include "doc/convert/attribute_convert/multivalue_attribute_convertor.h"
#include "doc/convert/attribute_convert/singlevalue_attribute_convertor.h"
#include "doc/convert/attribute_convert/string_attribute_convertor.h"

#include "hawking/indexlib/index_config.pb.h"

namespace hawking {
namespace indexlib {

bool GetFieldHash(
    const FieldConfig& field_config, const util::FieldValue* field_value, uint64_t* term);

std::shared_ptr<AttributeConvertor> CreateMultiAttrConvertor(const FieldConfig& attr_config);
std::shared_ptr<AttributeConvertor> CreateSingleAttrConvertor(const FieldConfig& attr_config);

class IndexDocFieldConvertor {
public:
    IndexDocFieldConvertor(std::shared_ptr<IndexlibIndexConfig> index_config) {
        Init_(index_config);
    }
    ~IndexDocFieldConvertor() = default;

    bool ConvertIndexField(
        std::shared_ptr<NormalDocument> doc, const FieldConfig& field_config,
        const util::FieldValue* field_value);
    
    bool ConvertAttributeField(
        std::shared_ptr<NormalDocument> doc,
        int32_t field_id,
        const FieldConfig& field_config,
        const util::FieldValue* field_value = nullptr);

private:
    void Init_(std::shared_ptr<IndexlibIndexConfig> index_config);

    std::vector<std::shared_ptr<AttributeConvertor>> attr_convertors_;
};

}
}